package com.xsmart.oa.dao.mall.mymenu;

import com.xsmart.common.entity.user.InfsUsers;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface RegisterDao {
    @Select("select * from INFS_USER where user_name=#{userName} ")
    Map<String,Object> findByUsername(@Param("userName") String userName);

    @Insert("insert into INFS_USER(user_name,password,question,answer,sex,birthday,mobile_phone,reg_time,user_picture,nick_name) " +
            "values(#{user.userName},#{user.password},#{user.question},#{user.answer},#{user.sex}," +
            "DATE_FORMAT(#{user.birthday},'%Y-%m-%d'),#{user.mobilePhone},DATE_FORMAT(#{user.regTime},'%Y-%m-%d %H:%i:%S')," +
            "#{user.userPicture,jdbcType=CLOB},#{user.nickName})")
    @Options(useGeneratedKeys = true, keyProperty = "user.userId",keyColumn = "user_id")
    int register(@Param("user") InfsUsers user);

    @Select("select * from INTU_WX_USER_INFO where openid=#{openid} ")
    Map<String,Object> findUserByOpenid(@Param("openid") String openid);

    @Insert("insert into intu_wx_user_info(user_id,openid) " +
            "values(#{userId},#{openid})")
    int insertIntuWxUserInfo(Map<String,Object> userExtMap);

    @Update({"update INFS_USER set user_picture = #{user.userPicture,jdbcType=CLOB},nick_name = #{user.nickName},sex=#{user.sex}," +
            "last_login=DATE_FORMAT(#{user.lastLogin},'%Y-%m-%d %H:%i:%S'),last_mod_time=DATE_FORMAT(#{user.lastModTime},'%Y-%m-%d %H:%i:%S') where user_id = #{user.userId}"})
    int updateInfsUser(@Param("user") InfsUsers user);

    /**
     * 获取用户的类型
     * @param userId
     * @return
     */
    @Select("SELECT user_type from infs_user where user_id=#{userId}")
    List<Integer> getUserType(@Param("userId") Integer userId);
}
